import { Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { createVNode } from 'vue';
import md5 from 'js-md5';

const hashSuffix: string = 'U2FsdGVkX18IcV95iH773nhijOCNXT2SoV1vFU5OuXTpzVK1cXqXRw==';

/**
 * 得到浏览器高度
 * @returns 
 */
export function getWindowHeight(): number {
    return document.compatMode === "CSS1Compat"
        ? document.documentElement.clientHeight
        : document.body.clientHeight;
}

/** 
 * 封装确认弹出框
 */
export function confirm(title: string, content: string) {
    return new Promise((resolve, reject) => {
        Modal.confirm({
            title: title,
            icon: createVNode(ExclamationCircleOutlined),
            content: content,
            onOk() {
                resolve(true);
            },
            onCancel() {
                reject(false);
            },
        });
    }).catch(() => { return false; });
}

/**
     * 首字母转小写
     * @param str 
     * 字符串
     */
export function toCamelCase(str: string): string {
    if (!str || !str.length) {
        return str;
    }
    if (str.length === 1) {
        return str.charAt(0).toLowerCase();
    }
    return str.charAt(0).toLowerCase() + str.substr(1);
}

/**
 * MD5加密
 * @param value 
 * @returns 
 */
export function getMd5Suffix(value: string): string {
    return md5(value + hashSuffix);
}